package demo8;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration//告诉Spring这是一个配置类
@ComponentScan("demo8")//告诉Spring要扫描的包
public class Config {

    /**
    @Bean注解可以向容器主动注册对象.
    方法名叫什么都可以,只要添加该注解,那么返回的对象就会被存入Spring容器中
     */
    @Bean
    public Student s(){
        return new Student();
    }

    @Bean
    public DruidDataSource dataSource(){
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
        datasource.setUsername("root");
        datasource.setPassword("root");
        return datasource;
    }
}
